package com.miyake.client.tools;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;

public class WaitPopup extends PopupPanel {

	private static WaitPopup popup = new WaitPopup();
	private static int count = 1;
	private static int total = 1;
	private static HTML status;
	private WaitPopup() {
		super(true);
		VerticalPanel panel = new VerticalPanel();
		this.setAutoHideEnabled(false);
		HTML lblNewLabel = new HTML("<h3>Please wait...</h3>");
		lblNewLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		
		panel.add(lblNewLabel);
		if (status == null) {
			status = new HTML();
		}
		panel.add(status);
		setWidget(panel);
		lblNewLabel.setSize("100%", "100%");
	}

	public static void showPopup() {
		popup.center();
		WaitPopup.count = 0;
		WaitPopup.total = 1;
		status.setText("");
	}
	
	public static void showPopup(int count) {
		popup.center();
		WaitPopup.count = 0;
		WaitPopup.total = count;
		status.setText("");
	}
	public static void hidePopup() {
		WaitPopup.count++;
		status.setHTML("<h3>" + count + "/" + total + "</h3>");
		if (WaitPopup.count == total) {
			popup.hide();
		}
	}
	
	public static boolean isPopupVisible() {
		return popup.isShowing();
	}
}
